package com.dftdla.server.handler;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.dftdla.dao.mapper.UserGroupMapper;
import com.dftdla.dao.pojo.UserGroup;
import com.dftdla.dao.service.UserGroupService;
import com.dftdla.result.ResponseResult;
import com.dftdla.server.message.request.GroupMembersRequestMessage;
import com.dftdla.util.Code;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;
import java.util.Set;

/**
 * @author 14501
 */
@Slf4j
@Component
@ChannelHandler.Sharable
public class GroupMembersRequestMessageHandler extends SimpleChannelInboundHandler<GroupMembersRequestMessage> {

    @Resource
    private UserGroupMapper userGroupMapper;

    @Override
    protected void channelRead0(ChannelHandlerContext ctx, GroupMembersRequestMessage msg) {
        List<Long> ids = userGroupMapper.getGroupMembers(msg.getGroupId());
        ctx.writeAndFlush(new TextWebSocketFrame(new ResponseResult<>(Code.SUCCESS,ids).toString()));
    }
}
